package org.wattdepot.cli.command;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the ListPowerForTimeCommand command handler.
 * 
 * @author George Lee
 *
 */
public class TestPowerCommand extends CommandTestBed {

  /**
   * Tests the doCommand method of the ListPowerForTimeCommand class.
   */
  @Override
  @Test
  public void testDoCommand() {
    String command, result;
    PowerCommand listCommand = new PowerCommand(this.client);
    
    //Valid command:
    //power generated SIM_OAHU_GRID timestamp 2009-11-01T10:10:10.000-10:00
    command = "power foo SIM_OAHU_GRID timestamp 2009-11-01T10:10:10.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking the command is invalid.",
        result.contains(WattDepotCliCommand.PARAMETER_ERROR));
    
    command = "power generated SIM_OAHU_GRID foo 2009-11-01T10:10:10.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking the command is invalid.",
        result.contains(WattDepotCliCommand.PARAMETER_ERROR));
    
    command = "power generated SIM_OAHU_GRID timestamp foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the timestamp result is invalid.",
        result.contains(WattDepotCliCommand.TSTAMP_ERROR));
    
    command = "power generated foo timestamp 2009-11-01T10:10:10.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the source is invalid",
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
    
    command = "power generated SIM_OAHU_GRID timestamp 2009-11-01T10:10:10.000-10:00";
    result = listCommand.doCommand(command);
    assertFalse("Checking that the timestamp is valid.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    assertFalse("Checking that the source is valid",
        result.startsWith("Could not find the source '"));
    assertTrue("Checking that there is a valid result from the operation.", 
        Double.valueOf(result) >= 0);
    
    command = "power consumed SIM_OAHU_GRID timestamp 2009-11-01T10:10:10.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking that there is a valid result from the operation.", 
        Double.valueOf(result) >= 0);
  }
}
